//
//  NWHomeRetweedCell.swift
//  Weibo01
//
//  Created by 牛威 on 15/12/13.
//  Copyright © 2015年 牛威. All rights reserved.
//

import UIKit

//MARK: - 转发微博的cell

class NWHomeRetweedCell: NWHomeCell {
    
    
    //MARK: -  继承父类的模型属性
     //需要override 
    //不需要super
    //先调用父类的属性 再调用子类的属性
    
   override var arrayM : HMViewModel? {
    
        didSet {
            
            //设置转发内容
            
            retWeetedLabel.text = arrayM?.retweedText
        
            picture.snp_updateConstraints { (make) -> Void in
                
                //判断配图的有无

                let offset = arrayM?.thumbnailUrls?.count > 0 ? TopViewMargin : 0
                
                //让无配图的时候retWeetedLabel的间距为一个margin
                
              make.top.equalTo(retWeetedLabel.snp_bottom).offset(offset)

            }
            
        
        }
    
    }

    override func setupUI() {
        
        super.setupUI()
        
        
        addRetweedSub()
        
    }
    
    
    //懒加载控件
    /// 背景button
    private lazy var backBtn : UIButton = {
     
        let btn = UIButton()
        
        btn.backgroundColor = UIColor(white: 0.9, alpha: 1)  //UIColor.redColor()
    
        return btn
    
    }()
    /// 转发label
     lazy var  retWeetedLabel : UILabel = UILabel(
        title: "转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转",
        fontSize: 14,
        color: UIColor.darkGrayColor(),
        screenInserts: TopViewMargin)
    
    

}



//MARK: - 设置界面

extension NWHomeRetweedCell {

    private func addRetweedSub(){
        
        //1添加控件
        
        contentView.insertSubview(backBtn, belowSubview: picture)
        contentView.insertSubview(retWeetedLabel, aboveSubview: backBtn)
        
        //2设置布局
        
        backBtn.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(contentLabel.snp_bottom).offset(TopViewMargin)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.bottom.equalTo(bottomView.snp_top)
        }
        
       retWeetedLabel.snp_makeConstraints { (make) -> Void in

          make.top.equalTo(backBtn.snp_top).offset(TopViewMargin)
          make.left.equalTo(backBtn.snp_left).offset(TopViewMargin)
        }
        
        picture.snp_makeConstraints { (make) -> Void in

            make.top.equalTo(retWeetedLabel.snp_bottom).offset(TopViewMargin)
            make.left.equalTo(retWeetedLabel.snp_left)

            make.width.equalTo(300)
            make.height.equalTo(90)
        }
        
        
        
        
    }



}
